package pyrachnid.ctrl.listener;

import Event.Operation.AllocateCell;
import Event.Operation.LightFire;
import Event.Operation.DesallocateCell;
import Event.Operation.Extinguish;
import pyrachnid.ctrl.Observer;
import pyrachnid.ctrl.Simulator;
import pyrachnid.model.ground_model.Cell;
import pyrachnid.view.MainWindow;

public class listenerCell extends Observer {

	public listenerCell(Simulator p_sim, MainWindow p_view) {
		super(p_sim, p_view);
	}

	@Override
	public void update(Object p_o, String p_arg) {
		Cell cell = (Cell) p_o;
		if(p_arg.equals("Fire"))
		{
			System.out.println("INFO : Cell in : x=" + cell.getPositionX() + " y=" + cell.getPositionY() + " is in fire in " + this.getClass().getName());
			cell.getFire().attach(new listenerFire(_simulator, _view));
			_view.getPanneau().addFireImage(cell);
			cell.addOperation(new LightFire(cell, cell.getFire().getFireIntensity()));
		}
		else if(p_arg.equals("Extinguish Fire"))
		{	
			System.out.println("INFO : Fire in : x=" + cell.getPositionX() + " y=" + cell.getPositionY() + " is extinguished in " + this.getClass().getName());
			cell.addOperation(new Extinguish(cell));
		}
		else if(p_arg.equals("Allocated"))
		{
			System.out.println("INFO : Fire in : x=" + cell.getPositionX() + " y=" + cell.getPositionY() + " is Allocated in " + this.getClass().getName());
			cell.addOperation(new AllocateCell(cell, cell.getFire().getFireIntensity()));
		}
		else if(p_arg.equals("Not allocate"))
		{
			System.out.println("INFO : Fire in : x=" + cell.getPositionX() + " y=" + cell.getPositionY() + " is Free in " + this.getClass().getName());
			cell.addOperation(new DesallocateCell(cell));
		}
	}
}